package com.sun.common.pojo;

import com.alibaba.fastjson2.JSON;
import lombok.Data;

/**
 * 全局返回结果
 */
@Data
public class Result<T> {

    private Boolean success   = false;

    private String  errorCode = "";

    private String  errorMsg  = "";

    private T       value;

    public Result() {
        super();
    }

    public Result(boolean success) {
        super();
        this.success = success;
    }

    public Result(T value) {
        super();
        this.success = true;
        this.value = value;
    }

    public Result(String errorMsg) {
        super();
        this.errorMsg = errorMsg;
    }

    public Result(String errorCode, String errorMsg) {
        super();
        this.errorCode = errorCode;
        this.errorMsg = errorMsg;
    }

    public static Result<Boolean> success() {
        Result<Boolean> result = new Result<>();
        result.setSuccess(true);
        return result;
    }

    @Override
    public String toString() {
        return JSON.toJSONString(this);
    }

}
